package com.xy.p2p.service.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import com.xy.core.util.BeanUtil;
import com.xy.common.page.Pagination;
import com.xy.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.xy.p2p.dao.TmemberratesDao;
import com.xy.p2p.model.Tmemberrates;
import com.xy.p2p.service.TmemberratesService;

@Service
@Transactional
public class TmemberratesServiceImpl extends BaseServiceImpl<Tmemberrates> implements
		TmemberratesService {
	private TmemberratesDao tmemberratesDao;

	public TmemberratesServiceImpl(TmemberratesDao paramAppRoleDao) {
		super(paramAppRoleDao);
		this.tmemberratesDao = paramAppRoleDao;
	}

	@Override
	public boolean checkExist(String paraName, String paraValue) {
		return tmemberratesDao.checkExist("Tmemberrates", paraName, paraValue);
	}

	@Override
	public List<Tmemberrates> getTmemberrates(Map<String, Object> map) {
		return tmemberratesDao.getTmemberrates(map);
	}
	@Override
	public Pagination getTmemberratesByPage(Map<String, Object> map, int pageNo,
			int pageSize) {
		// TODO Auto-generated method stub
		return tmemberratesDao.getTmemberratesByPage(map, pageNo, pageSize);
	}
	 
   @Override
	public Tmemberrates save(Tmemberrates tmemberrates) {
//		tmemberrates.setModtime(new Date());
		if(tmemberrates.getMrid()==null){
			//新增
        	return super.save(tmemberrates);
		}else{
			//更新
			Tmemberrates tmemberrates1=tmemberratesDao.get(tmemberrates.getMrid());
			try {
				BeanUtil.copyNotNullProperties(tmemberrates1, tmemberrates);
			} catch (Exception e) {
				e.printStackTrace();
			}  
			return super.save(tmemberrates1);
		}
	}
   @Override
   public Tmemberrates getWITHDRAW_FEE(){
	   Map<String , Object> queryMap =new HashMap<String, Object>();
	   queryMap.put("feedcode", Tmemberrates.WITHDRAW_FEE);
	   return tmemberratesDao.getTmemberrates(queryMap).get(0);
   }
   
   @Override
	public Tmemberrates getYED_early(String limit) {
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("feedcode", Tmemberrates.PRE_YED_EARLY + limit);
		List<Tmemberrates> list = tmemberratesDao.getTmemberrates(queryMap);
		if (list.size() <= 0)
			return null;
		else
			return list.get(0);
	}

	@Override
	public Tmemberrates getFee(String feedcode) {
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("feedcode", feedcode);
		List<Tmemberrates> list = tmemberratesDao.getTmemberrates(queryMap);
		if (list.size() <= 0)
			return null;
		else
			return list.get(0);
	}

}